home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DDJ0992.ARJ / README < prev    next >
Text File  |  1992-07-05  |  15KB  |  320 lines

  1. This is the source for the X-Sharp 3-D animation package, version 21,
  2. as presented in the Graphics Programming column in Dr. Dobb's
  3. Journal, as of the October 1992 issue.  Fast, assembly-language texture
  4. mapped polygons have been added since the last version, version 20. 
  5. The code has been tested with Borland C++ 3.0 and TASM 3.0.  To make
  6. the X-Sharp demo program DEMO1, run K1.BAT.  When you run DEMO1, I
  7. suggest you use the '0' key to turn on a spotlight, then use the 'S'
  8. key to speed up the rotation and switch between X, Y, and Z as the
  9. axis of rotation.  Also keep an eye peeled for "ursanauts"!
  10.  
  11. Unpack this archive with PKUNZIP -d; the ball generation code belongs
  12. in the .\BALL subdirectory, and, because it has some of the same
  13. filenames as the main directory, problems will result without -d.
  14.  
  15. Files in this archive:
  16.  
  17. APPROT.C     - appends rotations in X, Y, and Z
  18. BALL         - subdirectory containing ball-generation code; see below
  19. BALVERT0.INC - include file generated by .\BALL\GENBALL that defines
  20.                 ball-shaped object
  21. COLOR.C      - RGB space -> adapter palette space color mapping, color
  22.                intensity adjustment
  23. COSTABLE.INC - include file for fixed-point cosines between 0 and 90 degrees,
  24.                 generated by GENCOS
  25. DEMO1.C      - X-Sharp demo program
  26. DEMO1.EXE    - demo program built by running K1.BAT
  27. DRAW.ASM     - draws the scanned-out pixels of a convex polygon in mode X
  28. DRAWPOBJ.C   - draws a polygon-based object
  29. DRAWTEX.ASM  - assembly-language implementation of inner-loop texture drawing
  30. DRAWTEXP.C   - draws a texture-mapped polygon
  31. FILLCNVX.C   - fills a convex polygon
  32. FILLRECT.ASM - fills a rectangle with a solid color in mode X
  33. FIXED.ASM    - fixed point arithmetic routines
  34. GAMMA        - subdirectory containing gamma correction table generation
  35.                 program
  36. GENCOS.C     - generates cosine table for fixed-point look-up
  37. GLOBALS.C    - global variables
  38. INITBALL.C   - initializes the ball-shaped object
  39. INITFIX.C    - initializes fixed-point data
  40. INITLIGH.C   - sets up initial illumination (ambient and diffuse lighting)
  41. INITPAL.C    - sets up the adapter color palette
  42. K1.BAT       - remakes X-Sharp, producing demo program DEMO1
  43. LIGHTING.C   - illumination control
  44. LINKRESP     - TLINK response file
  45. MAKEFILE     - Borland Make makefile
  46. MODE.ASM     - initializes the screen to mode X (320x240, 256 colors)
  47. MOVEOBJ.C    - updates the position and orientation of polygon-based objects
  48. OLIST.C      - object list initialization, handling, and sorting
  49. POLYGON.H    - polygon & 3-D header file
  50. README       - this file
  51. SCAN.ASM     - scans out an edge of a convex polygon
  52. SHOWPAGE.ASM - selects the video page that's visible
  53. TURBOC.CFG   - Borland C++ 3.0 configuration file.  Uses 3.0-specific
  54.                 options, which must be changed for 2.0 and earlier
  55. XFPROJ.C     - transforms and projects polygon-based objects
  56. XSHARP21     - ID file for the X-Sharp version
  57.  
  58. The subdirectory .\BALL contains the source code and executable for
  59. the program GENBALL, which creates the vertex and face lists for a
  60. ball made from rectangular faces (BALVERT0.INC was created by GENBALL).
  61. Remake GENBALL by running K.BAT in the .\BALL directory.  See the
  62. 12/29/91 log entry for details.
  63.  
  64. Note that TURBOC.CFG specifies full optimization for BC++ 3.0 with
  65. -O2 -Oa.  You will have to change these switches for earlier versions
  66. of BC++.
  67.  
  68. Note that this code uses 386-specific instructions unless USE386 is
  69. set to 0 in FIXED.ASM.  With USE386 set to 0, the demo will run on an 8088
  70. or 286, but performance is poor except on a very fast 286.  Performance is
  71. quite good on a 20 MHz 386, and very good--30 to 60 frames per second--on
  72. a 33 MHz 486.
  73.  
  74. Comments and questions may be directed to me in the following ways:
  75.  
  76. Bix: graphic.disp or graphic.pgms conferences or Bixmail (mabrash)
  77. MCI mail (mabrash)
  78. M&T Online programming.graphics conference (mabrash)
  79. U.S. Mail (7 Adirondack Street, South Burlington, VT 05403)
  80.  
  81. I will do my best to respond, time permitting.  No guarantees.
  82.  
  83. Bix is the best way to get hold of me.
  84.  
  85. This material may be used freely; it is provided free of charge, as
  86. are responses to questions and comments, within reason.  Should the
  87. spirit move you, a contribution to the Vermont Assocation for the
  88. Blind and Visually Impaired, sent care of Dr. Dobb's Journal, myself,
  89. or directly to VABVI, would be appreciated, and would motivate me to
  90. keep enhancing X-Sharp.  Please make checks payable to the Vermont
  91. Association for the Blind and Visually Impaired.
  92.  
  93. Vermont Association for the Blind and Visually Impaired
  94. 37 Elmwood Avenue
  95. Burlington, VT 05401
  96.  
  97. Dr. Dobb's Journal
  98. 411 Borel Avenue, Suite 100
  99. San Mateo, CA 94403-3522
  100.  
  101. *****************************************************************
  102. * This code is provided as-is, with no warranties of any sort.  *
  103. * So far as I know, it works fine, but use it at your own risk! *
  104. *****************************************************************
  105.  
  106. --Michael Abrash  7/5/92
  107.  
  108.  
  109.                      ******************
  110.                      * Log of changes *
  111.                      ******************
  112.  
  113. **********************************************************************
  114. Begin entry for 7/5/92
  115.  
  116. ----------
  117. Implemented single-scan-line texture-map drawing (inner loop for drawing
  118. texture-mapped polygons) in reasonably tight assembly language in
  119. DRAWTEX.ASM.  Also changed texture-map algorithm to half-include all
  120. texture-map pixels that map to edges, so that textures will remain
  121. reasonably symmetric as the destination polygons to which they are
  122. mapped rotate.
  123.  
  124. **********************************************************************
  125. Begin entry for 6/10/92
  126.  
  127. ----------
  128. Added texture-mapped polygons, drawn by DRAWTEXP.ASM.  Implementation
  129. is currently in C and not particularly fast, but does work pretty
  130. well.  There are rough edges remaining in which source pixels get
  131. mapped to which destination pixels; right now, things follow the
  132. standard polygon edge rules, which hold that pixels exactly on the
  133. right and bottom edges aren't drawn.  This causes slightly different
  134. portions of the image to be mapped in depending on the orientation of
  135. the destination polygon.  Also, there are some problems resulting from
  136. the use of truncated integers as screen coordinates.  Still, the results
  137. look good and don't miss any destination pixels, so the code is
  138. certainly usable right now.
  139.  
  140. **********************************************************************
  141. Begin entry for 5/2/92
  142.  
  143. ----------
  144. Altered DRAW.ASM to draw as much as possible a word at a time.
  145.  
  146. **********************************************************************
  147. Begin entry for 4/3/92
  148.  
  149. ----------
  150. Implemented support for 8088 and 286 fixed-point math in FIXED.ASM.
  151. Previously, only 386 and up processors were supported.  See comments in
  152. FIXED.ASM for limitations of the 8088/286 version of FixedDiv().
  153.  
  154. ----------
  155. Altered the polygon Face structure so that the first vertex in the vertex
  156. list (VertNums) for any shaded polygon must now be the endpoint of a unit
  157. normal vector that has the second vertex in the vertex list as the
  158. startpoint. This unit vector is then transformed along with the rest of the
  159. polygon, and is used for calculating diffuse shading.  Note that the first
  160. vertex in the polygon's vertex list is *not* a vertex of the actual polygon,
  161. just the endpoint of the unit normal.  However, the second vertex in the
  162. polygon's vertex list *is* a vertex of the actual polygon.  Look at
  163. GENBALL.C, in subdirectory BALL, to see an example of the creation of
  164. polygon vertices and face lists.  Note that NumVerts in the polygon
  165. Face structure does not count the first (unit-normal endpoint) vertex.
  166.  
  167. Changed XFPROJ.C so that unit normal endpoints are only transformed into
  168. view space, not into screen space or screen coordinates.  Since the unit
  169. normals are useless once they're transformed into screen space (they're not
  170. normals at that point, because perspective transformation doesn't preserve
  171. angles), there's no reason to waste time transforming them into screen space,
  172. so we don't.  This requires that the unit normal endpoints *always* be the
  173. last endpoints in an object's vertex list, and that NumRealVerts (a new entry
  174. in the PObject structure) now specifies how many real polgyon vertices there
  175. are (that is, how many vertices there are excluding unit normal endpoints),
  176. so that XFPROJ.C knows to only transform NumRealVerts vertices into screen
  177. space.
  178.  
  179. ----------
  180. Implemented a full-color color model.  Polygon colors are now described as
  181. RGB triples, with 8 bits of resolution for each color component.  These
  182. colors are stored in ModelColor structures.  There is a ModelColor entry
  183. in each polygon's Face structure.  There is also a ColorIndex entry,
  184. specifying a direct color index to be used for drawing the polygon; this is
  185. equivalent to the previous style of drawing polygons, and is used only for
  186. unshaded (unilluminated) polygons.  Of course, the VGA doesn't have 24 bits
  187. per pixel.  InitializePalette(), in INITPAL.C, sets up the palette however
  188. you'd like; currently with 64 levels each of pure red, green, and blue, and
  189. 2 levels each of red, green, and blue for mixing.  This is a good model for
  190. displaying pure primary colors, but suffers severe color quantization for
  191. mixed colors.  ModelColorToColorIndex(), in COLOR.C, maps colors from the
  192. model 24-bit RGB color space into the actual available palette.  Note that
  193. InitializePalette() and ModelColorToColorIndex() are designed as replaceable
  194. modules, so any desired adapter-specific color mapping can easily be
  195. implemented; the rest of X-Sharp works in 24-bit RGB space.
  196.  
  197. ----------
  198. Implemented two types of shading:  ambient and diffuse (Lambert).  Ambient
  199. shading is nondirectional illumination, basically background light.
  200. Diffuse shading is directed illumination, treated as illumination by
  201. infinitely distant spotlights in X-Sharp and defined by a unit vector for
  202. direction and an RGB intensity for illumination level.  Added the ShadingType
  203. field to the polygon Face structure to select either, both, or neither of
  204. AMBIENT_SHADING and DIFFUSE_SHADING.  Modified DRAWPOBJ.C to perform the
  205. selected shading, using the unit normal of each polygon (discussed above),
  206. the RGB color of the polygon, the unit vector of each spotlight, and the
  207. intensity of each spotlight to calculate the shading for each polygon.
  208. Created the ModelIntensity structure to describe ambient and spotlight
  209. intensity levels as fixed-point RGB values.  Added a variety of functions
  210. to control illumination in LIGHTING.C.  Added InitializeLighting() to set
  211. up the initial lighting state.
  212.  
  213. ----------
  214. Implemented main program DEMO1.C, which displays a shaded, faceted ball with
  215. ambient lighting and three user-controllable spotlights, as well as
  216. user-controllable positioning, as the current X-Sharp demo program.  This
  217. replaces the previous demo program XS.C.
  218.  
  219. ----------
  220. Modified INITBALL.C to support the new polygon format, new color model, and
  221. shading.  The ball now has 71 faces that are illuminated with both diffuse
  222. and ambient shading, and 1 unshaded face that always has a constant color,
  223. yellow.
  224.  
  225. ----------
  226. Eliminated INITCUBE.C.
  227.  
  228. ----------
  229. Renamed MOVEPOLY.C to MOVEOBJ.C and changed function RotateAndMovePObject()
  230. to handle movement events set in main() and renamed the function to
  231. RotateAndMoveBall().
  232.  
  233. ----------
  234. Modified .\BALL\GENBALL.C to generate the new polygon format, with the
  235. first vertex for each face now the endpoint of a unit normal coming out of
  236. the second vertex.  The first vertex is not a part of the polygon, but is
  237. only used to determine the polygon's orientation.  See the above entry on
  238. the polygon Face structure for details.
  239.  
  240. ----------
  241. Other, minor changes such as the addition of some macros have been made.  I'm
  242. afraid I don't remember 'em all...
  243.  
  244. End entry for 4/3/92
  245. **********************************************************************
  246. Begin entry for 1/5/92
  247.  
  248. ----------
  249. Altered ConcatXforms to add in the translation element from matrix #1
  250. only when multiplying by the fourth column of matrix #2, because only
  251. the fourth column has a 1 at the bottom.  This fixes a bug in earlier
  252. versions that showed up when a world->view transformation involving
  253. translation was used.
  254.  
  255. ----------
  256. Removed setting of non-existent element XformToWorld[3][3] in INITCUBE.C
  257. and INITBALL.C.
  258.  
  259. End entry for 1/5/92
  260. **********************************************************************
  261. Begin entry for 12/29/91
  262.  
  263. ----------
  264. Converted XformVec and ConcatXforms to assembly language, reducing
  265. transformation and concatenation time to 5% or less of total time.
  266.  
  267. ----------
  268. Converted sin() and cos() calls to calls to the assembly language
  269. function CosSin(), which performs a table look-up.  Changed angle
  270. representations from radians to tenths of degrees to facilitate table
  271. look-up and to maximize accuracy.
  272.  
  273. ----------
  274. Put all the assembly language functions in fixed.asm, replacing
  275. l4.c and l9.asm.
  276.  
  277. ----------
  278. Deleted one cube from the animation, and substituted a ball.  The
  279. ball has a radius of 25, slightly larger than the cube it replaces.
  280. It has 6 bands of 12 facets each, for a total of 72 faces,
  281. approximately doubling the number of polygons in the animation, and
  282. has 62 vertices, increasing the number of vertices by more than 50%.
  283. Added INITBALL.C to initialize the ball, and added a call to
  284. InitializeBalls() to create the ball in main().  Only one ball is
  285. created, but more balls could easily be added, and the size of and
  286. number of bands in the ball(s) could easily be changed.
  287.  
  288. The program GENBALL, in .\BALL, generates all vertex and face info
  289. for a generic ball (it doesn't generate the color info, which varies
  290. from instance to instance).  The number of bands of faces and the
  291. size of the ball are prompted for when GENBALL is run.  The output of
  292. GENBALL with 6 bands and a radius of 25 is in BALVERT0.INC, and is
  293. included in INITBALL.C, which initializes a ball for use in the
  294. animation program.  To change the size, just regenerate BALVERT0.INC
  295. by running GENBALL with bands = 6 and the desired radius.  To change
  296. the number of bands, run GENBALL with the desired number of bands and
  297. radius, and then change the Colors array in INITBALL.C to have one
  298. color entry for each face in the new ball. (The number of faces is
  299. shown as a define at the top of the output file from GENBALL.) 
  300. Additional balls may be added by changing NUM_BALLS, and by adding a
  301. new entry to each array at the top of GENBALL.C.
  302.  
  303. ----------
  304. Changed object list from an array to a linked list that is sorted
  305. in back-to-front order after each set of moves, so drawing the list
  306. in order performs proper hiding of objects.
  307.  
  308. ----------
  309. Renamed source files more meaningfully, and renamed executable XS.EXE.
  310.  
  311. ----------
  312. Added a center (0,0,0) point to each object, which is transformed into
  313. view space each time the object is transformed.  This is used for
  314. Z-sorting objects for drawing precedence purposes, and can also be
  315. used for collision detection and the like.
  316.  
  317. End entry for 12/29/91
  318. **********************************************************************
  319.  
  320.